package scheduledtasks;



import scheduledtasks.entity.TaskObj;
import scheduledtasks.hander.MainHander;
import scheduledtasks.hander.SpringArawaHander;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

public class Apiimpl implements Api {

    @Override
    public boolean refCache(CopyOnWriteArrayList<TaskObj> copyOnWriteArrayList) {
        MainHander.copyOnWriteArrayList=copyOnWriteArrayList;
        return true;
    }


    @Override
    public void runScheduled(Integer id) {
       List<TaskObj> copyOnWriteArrayLists= MainHander.copyOnWriteArrayList;
       TaskObj taskObj=new TaskObj();
        for (TaskObj t:copyOnWriteArrayLists) {
            if(t.getId()==id){
                taskObj=t;
            }
        }
        try {
            SpringArawaHander.springInvokeMethod(taskObj.getClassName(),taskObj.getMethoName(),null);
        }catch (Exception e){
             e.printStackTrace();
        }

    }
}
